#!/bin/bash

cd /opt/gocron/result

arr=` kubectl get po -nfengchao|grep -v "NAME"|grep $1|awk '{print $1}' `
for pod in $arr # zts-hussar-web-main-744c799779-7dhw9
do
    echo "-----------------获取$pod日志-------------------------------"
    dr=${pod%-*}  # zts-hussar-web-main-744c799779
    dr1=${dr%-*}  # zts-hussar-web-main
    dr2=` date +%Y%m%d `  #  20230110
    dr3=${pod##*-} # 7dhw9

    mkdir -p $dr1/$dr2/$dr3
    kubectl exec -nfengchao $pod -- yum -y install tar >/dev/null 2>&1
	
    kubectl cp fengchao/$pod:/var/log/zts $dr1/$dr2/$dr3  >/dev/null 2>&1 # 旧门户日志位置
    kubectl cp fengchao/$pod:logs $dr1/$dr2/$dr3 >/dev/null 2>&1 # 新门户日志位置
    kubectl cp fengchao/$pod:/var/log/nginx $dr1/$dr2/$dr3  >/dev/null 2>&1  #nginx日志
done

